package som.simon.reactor;

import reactor.core.publisher.Flux;

public class CreateMain {

    public static void main(String[] args) {

        Flux.create(sink -> {
            // 创建用户上线监听
            UserStatusListener listener = new UserStatusListener(sink);
            // 异步模拟用户上线
            asyncUsersOnline(listener);

        }).log().subscribe();

    }

    private static void asyncUsersOnline(UserStatusListener listener) {
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                listener.online("党" + i);
            }
        }).start();
    }

}
